/**
 * SeismicPalette.java 2005. 6. 24.
 *
 * @copyrights 2004 PSIA Corp. All rights are reserved.
 */
package cs348a.color;

/**
 * A <code>SeismicPalette</code> defines a seismic palette.
 *
 * @author Taeksoo Jung, YoungJin Kim
 */
public final class SeismicPalette extends BasicPalette {
	/** Singleton instance */
	public static final SeismicPalette INSTANCE = getInstance();
	
	/**
	 * Constructor for <code>SeismicPalette</code>.
	 * 
	 * @param reds array of red components
	 * @param greens array of green components
	 * @param blues array of blue components
	 */
	private SeismicPalette(byte[] reds, byte[] greens, byte[] blues) {
		super("Seismic", reds, greens, blues);
	}
	
	/**
	 * Returns the singleton instance.
	 * 
	 * @return the singleton instance
	 */
	private static SeismicPalette getInstance() {
		// Creates arrays of components.
		byte[] reds = new byte[SIZE];
		byte[] greens = new byte[SIZE];
		byte[] blues = new byte[SIZE];

		// Constructs the components.
		for (int i = 0; i < SIZE; i++) {
			double f = (Math.max(0, Math.cos(((double) i / SIZE - 0.0) * 2.0 * Math.PI)) * 0.1 +
                Math.max(0, Math.cos(((double) i / SIZE - 1.0 / 4.0) * 2.0 * Math.PI)) * 0.00 +
                Math.max(0, Math.cos(((double) i / SIZE - 2.0 / 4.0) * 2.0 * Math.PI)) * 1.00 +
                Math.max(0, Math.cos(((double) i / SIZE - 3.0 / 4.0) * 2.0 * Math.PI)) * 1.00) * SIZE;
			reds[i] = cutOff(f);

			f = (Math.max(0, Math.cos(((double) i / SIZE - 0.0) * 2.0 * Math.PI)) * 0.1 +
                Math.max(0, Math.cos(((double) i / SIZE - 1.0 / 4.0) * 2.0 * Math.PI)) * 0.00 +
                Math.max(0, Math.cos(((double) i / SIZE - 2.0 / 4.0) * 2.0 * Math.PI)) * 1.00 +
                Math.max(0, Math.cos(((double) i / SIZE - 3.0 / 4.0) * 2.0 * Math.PI)) * 0.00) * SIZE;
           greens[i] = cutOff(f);

           f = (Math.max(0, Math.cos(((double) i / SIZE - 0.0) * 2.0 * Math.PI)) * 0.1 +
                Math.max(0, Math.cos(((double) i / SIZE - 1.0 / 4.0) * 2.0 * Math.PI)) * 1.00 +
                Math.max(0, Math.cos(((double) i / SIZE - 2.0 / 4.0) * 2.0 * Math.PI)) * 1.00 +
                Math.max(0, Math.cos(((double) i / SIZE - 3.0 / 4.0) * 2.0 * Math.PI)) * 0.00) * SIZE;
           blues[i] = cutOff(f);
		}
		
		return new SeismicPalette(reds, greens, blues);
	}
}
